package springapp.web.stereotype.controller;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import springapp.web.service.ProductFacade;


@Controller
public class InventoryController {
	

	protected final Log logger = LogFactory.getLog(getClass());

	@Autowired
	private ProductFacade productFacade;
	
	public InventoryController(){}
    
    @RequestMapping("/hello")
    public ModelAndView handleRequest(){
        String now = (new java.util.Date()).toString();
        logger.info("returning hello view with " + now);

        Map<String, Object> myModel = new HashMap<String, Object>();
        myModel.put("now", now);
        myModel.put("products", productFacade.getProducts());

        return new ModelAndView("hello", "model", myModel);
    }


    public void setProductFacade(ProductFacade productFacade) {
        this.productFacade = productFacade;
    }
    
    public ProductFacade getProductFacade() {
		return productFacade;
	}

}
